package logic

import (
	"context"
	"shape-erver/internal/svc"
	"shape-erver/internal/types"
	"shape-erver/utils"

	"github.com/tal-tech/go-zero/core/logx"
)

type CheckTaskStatusLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCheckTaskStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) CheckTaskStatusLogic {
	return CheckTaskStatusLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CheckTaskStatusLogic) CheckTaskStatus(req types.CheckTaskStatusReq) (*types.CheckTaskStatusResp, error) {
	// todo: add your logic here and delete this line

	statusInt, _ := utils.GetTaskGuidFromRedis(req.TaskId)
	var status string
	switch statusInt {
	case utils.PROCESSING:
		status = "processing" // 正在生成
	case utils.FAILED:
		status = "failed" // 生成失败
	case utils.SUCCESS:
		status = "success" // 生成成功
	case utils.CANCEL:
		status = "cancel" // 取消
	case utils.QUEUED:
		status = "queued" // 排队中
	default:
		status = "unknown" // 未知
	}
	return &types.CheckTaskStatusResp{Status: status, Message: status}, nil
	//
	//status := utils.GetTaskStatus(req.TaskId)
	//if status == "1" {
	//	return &types.CheckTaskStatusResp{Status: "ok"}, nil
	//} else {
	//	return &types.CheckTaskStatusResp{Status: status}, nil
	//}
	//return &types.CheckTaskStatusResp{}, nil
}
